package com.example.controller;

import com.example.entity.Article;
import com.example.entity.Comment;
import com.example.repository.ArticleRepository;
import com.example.repository.CommentRepository;
import com.example.service.ArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;
    @Autowired
    private CommentRepository commentRepository;
    @Autowired
    private ArticleRepository articleRepository;

    @RequestMapping("/findAll/{page}/{size}")
    public List<Article> find(@PathVariable Integer page,@PathVariable Integer size){
        PageInfo<Article> all = articleService.findAll(page,size);
        List<Article> list = all.getList();
        return  list;
    }


    @RequestMapping("/findCommentByArticle/{id}")
    public List<Article> findCommentByArticle(@PathVariable int id){
        List<Article> commentByArticle = articleService.findCommentByArticle(id);
        List<Comment> all = commentRepository.findByArticleId(id);
        System.out.println(all);
        return commentByArticle;
    }

    @RequestMapping("/findArtileByLabel/{id}")
    public List<Article> findArtileByLabel(@PathVariable int id){
        List<Article> artileByLabel = articleRepository.findArticleByLabel();
        System.out.println(artileByLabel);

        return  artileByLabel;
    }
}
